package com.lzx.iteam.adapter;

import android.content.Context;
import android.text.SpannableString;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.util.Constants;
import com.lzx.iteam.widget.TextViewSpan;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Megan on 15/10/14.
 */
public class TalkListCommentAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<Map<String,String>> talkUserDatas;

    public TalkListCommentAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void bindData(ArrayList<Map<String,String>> talkUserDatas) {
        this.talkUserDatas = talkUserDatas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return talkUserDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return talkUserDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        Map<String,String> userData = new HashMap<String, String>();
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.talk_list_comment_item, null);
            viewHolder.mContent = (TextView) convertView.findViewById(R.id.talk_list_comment_content);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        SpannableString user = new SpannableString(userData.get(Constants.TALK_USER_NAME));//回复人的名字
        TextViewSpan clickableSpan1 = new TextViewSpan(userData.get(Constants.TALK_USER_NAME), mContext, 0,0);
        clickableSpan1.setInfo(userData);
        user.setSpan(clickableSpan1, 0, userData.get(Constants.TALK_USER_NAME).length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        String replyName = "你大爷";
        SpannableString replyTo = new SpannableString(replyName);//回复人的名字
        TextViewSpan clickableSpan = new TextViewSpan(replyName, mContext, 0,0);
        clickableSpan.setInfo(userData);
        replyTo.setSpan(clickableSpan, 0, replyName.length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        viewHolder.mContent.setText("");
        viewHolder.mContent.append(user);
        viewHolder.mContent.append("回复");
        viewHolder.mContent.append(replyTo);
        viewHolder.mContent.append(":");
        viewHolder.mContent.append("你是不是傻啊？？");

        return convertView;
    }

    class ViewHolder {
        TextView mContent;
    }


}
